package com.google.code.toub.waves.editor.annotation;

/**
 * Class representing a color
 * 
 * @author ntoublanc
 * 
 */
public class AnnotationColor {
	/**
	 * Red composite of color.
	 */
	private int red;

	/**
	 * Green composite of color.
	 */
	private int green;
	/**
	 * Blue composite of color.
	 */
	private int blue;

	/**
	 * Constructor
	 * 
	 * @param red
	 *            red composite
	 * @param green
	 *            green composite
	 * @param blue
	 *            blue composite
	 */
	public AnnotationColor(int red, int green, int blue) {
		super();
		this.red = red;
		this.green = green;
		this.blue = blue;
	}

	/**
	 * Constructor
	 * 
	 * @param hexaDecimalColor
	 *            "#rrggvv" or "rrggvv" hexadecimal color representation
	 */
	public AnnotationColor(String hexaDecimalColor) {
		super();
		setHexaDecimalColor(hexaDecimalColor);
	}

	/**
	 * Set the hexadecimal color
	 * 
	 * @param hexadecimalColor
	 *            #rrggvv" or "rrggvv" hexadecimal color representation
	 */
	public void setHexaDecimalColor(String hexadecimalColor) {
		if (hexadecimalColor != null) {
			if (hexadecimalColor.startsWith("#")) {
				hexadecimalColor = hexadecimalColor.substring(1);
			}
			if (hexadecimalColor.length() == 6) {
				this.red = Integer.parseInt(hexadecimalColor.substring(0, 2),
						16);
				this.green = Integer.parseInt(hexadecimalColor.substring(2, 4),
						16);
				this.blue = Integer.parseInt(hexadecimalColor.substring(4, 6),
						16);
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return getAnnotationValue();
	}

	/**
	 * @return the "rgb(r,g,b)" value for this color
	 */
	public String getAnnotationValue() {
		return "rgb(" + red + "," + green + "," + blue + ")";
	}

	/**
	 * @return the "#rrggbb" representation of the color
	 */
	public String getHexadecimalRepresentation() {
		return String.format("#%1$02X%2$02X%3$02X", red, green, blue);
	}

	/**
	 * @return the red
	 */
	public int getRed() {
		return red;
	}

	/**
	 * @param red
	 *            the red to set
	 */
	public void setRed(int red) {
		this.red = red;
	}

	/**
	 * @return the green
	 */
	public int getGreen() {
		return green;
	}

	/**
	 * @param green
	 *            the green to set
	 */
	public void setGreen(int green) {
		this.green = green;
	}

	/**
	 * @return the blue
	 */
	public int getBlue() {
		return blue;
	}

	/**
	 * @param blue
	 *            the blue to set
	 */
	public void setBlue(int blue) {
		this.blue = blue;
	}
}
